﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Point = Game1942.Library.Background.Point;

namespace Game1942.Library.View
{
    public class ExplosionView : IView
    {
        private Texture2D explosionTexture;
        private SoundEffect explosionSound;
        private Point position;
        private Boolean visible;
        private int width, height;
        private double transparency;

        public ExplosionView(Point aPosition, int width,int height)
        {
            position = aPosition;
            this.width = width;
            this.height = height;
            visible = true;
            transparency = 1f;
        }

        public void LoadContent(Texture2D aTexture, SoundEffect explosionSound)
        {
            explosionTexture = aTexture;
            this.explosionSound = explosionSound;
        }

        public void Draw(SpriteBatch sprite)
        {
            if (Math.Round(transparency,2) == 0.8)
            {
                explosionSound.Play();
            }
            sprite.Draw(explosionTexture, new Rectangle(position.X, position.Y, width, height), Color.White * (float)transparency);
            transparency -= 0.05f;
            if (transparency == 0)
            {
                visible = false;
            }
            
        }

        public bool Visible()
        {
            return visible;
        }
    }
}
